<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app1" style="border: 1px solid black;">
    <h3>这是app1的作用域</h3>
    <my-component></my-component>
  </div>
  <div id="app2" style="border: 1px solid black;">
    <h3>这是app2的作用域</h3>
    <my-component></my-component>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
  <script>
    // 注册全局组件
    Vue.component('MyComponent', {
      template: `<button @click='addCount'>
                      全局组件，被点击次数是{{count}}
                  </button>`,
      data() {
        return {
          count: 0
        };
      },
      methods: {
        addCount() {
          this.count++;
        }
      }
    });
  
    // 创建Vue实例app1
    const app1 = new Vue({
      el: '#app1'
    });
  
    // 创建Vue实例app2
    const app2 = new Vue({
      el: '#app2'
    });
  </script>
</body>
</html>